package com.tuni.birthdaymoney.service.util.email.sender;

import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;

/**
 * Abstract class for email senders. Not an interface, because implements some
 * simple methods by invoking complicated one (adding necessary parameters
 * automatically).
 * 
 * @author Nikita Krenev
 */
public abstract class EmailSender {

    /**
     * Sends e-mail
     * 
     * @param title
     *            Title of email
     * @param body
     *            Body of email
     * @param sender
     *            Sender of email
     * @param directReceivers
     *            Email receivers
     * @param copyReceivers
     *            Email's copy receivers
     * @throws MessagingException
     *             Kinda common error
     */
    public abstract void send(String title, String body, InternetAddress sender, InternetAddress[] directReceivers, InternetAddress[] copyReceivers)
            throws MessagingException;
    
    /**
     * Sends e-mail (direct receivers only)
     * 
     * @param title
     *            Title of email
     * @param body
     *            Body of email
     * @param sender
     *            Sender of email
     * @param directReceivers
     *            Email receivers
     * @throws MessagingException
     *             Kinda common error
     */
    public void send(String title, String body, InternetAddress sender, InternetAddress[] directReceivers) throws MessagingException {
        send(title, body, sender, directReceivers, new InternetAddress[] {});
    }
    
    /**
     * Sends e-mail (single direct receiver only)
     * 
     * @param title
     *            Title of email
     * @param body
     *            Body of email
     * @param sender
     *            Sender of email
     * @param receiver
     *            Email receiver
     * @throws MessagingException
     *             Kinda common error
     */
    public void send(String title, String body, InternetAddress sender, InternetAddress receiver) throws MessagingException {
        send(title, body, sender, new InternetAddress[] {receiver}, new InternetAddress[] {});
    }
}